/*
 * @Author: NaturalHulk 2066634567@qq.com
 * @Date: 2024-02-18 18:02:59
 * @LastEditors: NaturalHulk 2066634567@qq.com
 * @LastEditTime: 2024-02-21 15:33:12
 * @FilePath: /lanting-haoran-architecture/src/pages/system/role/authUser.jsx
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import React, { useState, useEffect, useRef } from "react";
import { history, useParams, useRouteMatch } from "umi";
import { XHbutton, XHtable } from "@/components/xh-components/index";
import { allocatedUserList } from "@/api/system/role.ts";
const AuthUser = () => {
  // 表格枚举
  const columns = [
    {
      title: "用户编码",
      dataIndex: "userCode",
      key: "userCode",
      disabled: true,
    },
    {
      title: "用户名称",
      dataIndex: "userName",
      key: "userName",
    },
    {
      title: "用户昵称",
      dataIndex: "nickName",
      key: "nickName",
      inputType: "select",
    },
    {
      title: "部门名称",
      dataIndex: "deptName",
      key: "deptName",
    },
    {
      title: "邮箱",
      dataIndex: "email",
      key: "email",
    },
    {
      title: "手机",
      dataIndex: "phonenumber",
      key: "phonenumber",
    },
    {
      title: "状态",
      dataIndex: "status",
      key: "status",
    },
    {
      title: "到期天数",
      dataIndex: "expirationDay",
      key: "expirationDay",
    },
    {
      title: "到期时间",
      dataIndex: "expirationTime",
      key: "expirationTime",
    },
    {
      title: "创建时间",
      dataIndex: "createTime",
      key: "createTime",
    },

    // {
    //   title: "操作",
    //   width: "30%",
    //   render: (val) => {
    //     return (
    //       <XHoperate
    //         list={[
    //           {
    //             label: "修改",
    //             emit: () => edit(val),
    //             icon: <FormOutlined />,
    //           },
    //           {
    //             label: "删除",
    //             danger: true,
    //             emit: () => del(val),
    //             showMsg: true,
    //             icon: <DeleteOutlined />,
    //           },

    //           {
    //             label: "查看",
    //             emit: () => see(val),
    //             icon: <DeleteOutlined />,
    //           },
    //         ]}
    //       />
    //     );
    //   },
    //   width: "15%",
    // },
  ];

  // 各种状态
  const [state, setState] = useState({
    loading: false,
    show: false,
    title: "新增",
    btnLoading: false,
  });

  // 表格数据
  const [tableData, setTableData] = useState({
    data: [],
    total: 0,
    pagination: { pageNum: 1, pageSize: 10 },
  });

  // 列表分页
  const [query, setQuery] = useState({
    pageNum: 1,
    paheSize: 10,
    roleId: useParams().id,
  });

  //添加用户
  const addUser = () => {};

  //批量取消授权
  const revoke = () => {};

  //关闭
  const closeBack = () => {
    history.push("/system/role");
  };

  //获取列表
  const getList = async () => {
    try {
      setState({
        loading: true,
      });
      const res = await allocatedUserList(query);
      setTableData({
        data: res.rows,
        total: res.total,
      });
    } catch (err) {
      console.log(err);
    } finally {
      setState({
        loading: false,
      });
    }
  };

  return (
    <div className="app-container">
      <XHbutton
        list={[
          {
            label: "添加用户",
            emit: () => addUser(),
          },
          {
            label: "批量取消授权",
            emit: () => revoke(),
          },
          {
            label: "关闭",
            emit: () => closeBack(),
          },
        ]}
      />

      <XHtable
        loading={state.loading}
        columns={columns}
        rowSelection={null}
        dataSource={tableData.data}
        total={tableData.total}
        pagination={(val) => {
          getList({
            ...query,
            ...val,
          });
        }}
      />
    </div>
  );
};

export default AuthUser;
